package offer;

import java.util.Objects;
import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t 学生离开教室");
                countDownLatch.countDown();
            }, Objects.requireNonNull(CountyEnum.getVal(i)).getVal()).start();
        }

        try {
            // CountDownLatch只有为0的时候，才会释放当前锁
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName() + "\t 班长离开教室");

        System.out.println(CountyEnum.ONE);
        System.out.println(CountyEnum.ONE.getNum());
        System.out.println(CountyEnum.ONE.getVal());
    }
}
